import axios from 'axios'

import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

const http = axios.create({
  baseURL: 'http://127.0.0.1:8888/api/private/v1/'
})

http.interceptors.request.use(config => {
  if (sessionStorage.token) {
    config.headers.Authorization = sessionStorage.token
    Nprogress.start()
  }
  return config
}, err => {
  return Promise.reject(err)
})

http.interceptors.response.use(config => {
  Nprogress.done()
  return config
})

export default http
